package zdream.pmfield.test.data.foe;

import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Method;

import zdream.pmfield.data.foe.MoveTarget;
import zdream.pmfield.storage.MovesJsonLoader;

import static org.junit.Assert.*;
import static zdream.pmfield.data.foe.MoveBlastType.*;
import static zdream.pmfield.data.foe.MoveRouteType.*;
import static zdream.pmfield.data.foe.MoveTargetType.*;

/**
 * @author Zdream
 * @date 2023-12-21
 * @since 0.0.1
 */
public class MoveTargetCase {
	Method method;

	@Before
	public void initParseMoveTargetMethod() {
		try {
			method = MovesJsonLoader.class.getDeclaredMethod("parseMoveTarget", String.class);
			method.setAccessible(true);
		} catch (NoSuchMethodException e) {
			throw new RuntimeException(e);
		}
	}

	private MoveTarget parseMoveTarget(String text) {
		try {
			return (MoveTarget) method.invoke(null, text);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Test
	public void testParseMoveTarget() {
		MoveTarget target1 = parseMoveTarget(null);
		System.out.println("target1: " + target1);
		assertEquals(ENEMY, target1.type);
		assertArrayEquals(new int[] {0, 1, 2, 3}, target1.range);
		assertEquals(DIRECT, target1.route);
		assertEquals(SINGLE, target1.blast);

		MoveTarget target2 = parseMoveTarget("self");
		System.out.println("target2: " + target2);
		assertEquals(SELF, target2.type);
		assertArrayEquals(new int[] {0}, target2.range);
		assertEquals(DIRECT, target2.route);
		assertEquals(SINGLE, target2.blast);

		MoveTarget target3 = parseMoveTarget("seat:1-3");
		System.out.println("target3: " + target3);
		assertEquals(SEAT, target3.type);
		assertArrayEquals(new int[] {1, 2, 3}, target3.range);
		assertEquals(DIRECT, target3.route);
		assertEquals(SINGLE, target3.blast);

		MoveTarget target4 = parseMoveTarget(":2-3");
		System.out.println("target4: " + target4);
		assertEquals(ENEMY, target4.type);
		assertArrayEquals(new int[] {2, 3}, target4.range);
		assertEquals(DIRECT, target4.route);
		assertEquals(SINGLE, target4.blast);

		MoveTarget target5 = parseMoveTarget(":1,3-4");
		System.out.println("target5: " + target5);
		assertEquals(ENEMY, target5.type);
		assertArrayEquals(new int[] {1, 3, 4}, target5.range);
		assertEquals(DIRECT, target5.route);
		assertEquals(SINGLE, target5.blast);

		MoveTarget target6 = parseMoveTarget(":1:t");
		System.out.println("target6: " + target6);
		assertEquals(ENEMY, target6.type);
		assertArrayEquals(new int[] {1}, target6.range);
		assertEquals(THROW, target6.route);
		assertEquals(SINGLE, target6.blast);

		MoveTarget target7 = parseMoveTarget("::b:xOx");
		System.out.println("target7: " + target7);
		assertEquals(ENEMY, target7.type);
		assertArrayEquals(new int[] {0, 1, 2, 3}, target7.range);
		assertEquals(BEAM, target7.route);
		assertEquals(BLAST121, target7.blast);

		MoveTarget target8 = parseMoveTarget("seat:::Oxx");
		System.out.println("target8: " + target8);
		assertEquals(SEAT, target8.type);
		assertArrayEquals(new int[] {0, 1, 2, 3}, target8.range);
		assertEquals(DIRECT, target8.route);
		assertEquals(FORWARD211, target8.blast);

		MoveTarget target9 = parseMoveTarget("");
		System.out.println("target9: " + target9);
		assertEquals(ENEMY, target9.type);
		assertArrayEquals(new int[] {0, 1, 2, 3}, target9.range);
		assertEquals(DIRECT, target9.route);
		assertEquals(SINGLE, target9.blast);
	}
}
